<template>
	<view class="flex column space-between addAccompany width-full">
		<view class="paddingTop-20 userTitle flex box-sizing  space-between items-center">
			<view class="box-sizing paddingLeft-30" style="width: 120rpx;">
				<u-icon @click="uni.navigateBack()" name="arrow-left" :size="25"></u-icon>
			</view>
			<view style="flex: 1;padding-left: calc(10rpx);"
				class=" flex box-sizing  flex-center items-center height-full">
				<view class="fontSize-30 weight-700 marginRight-10">
					{{ stuentInfo.name + '(陪学记录)' }}
				</view>
			</view>
			<view class="right box-sizing paddingRight-50">
				<view @click="$u.throttle(submit, 500)"
					class="submit flex flex-center items-center fontSize-27 color-white">
					提交
				</view>
			</view>
			<!-- <view class=""></view> -->
		</view>
		<view class="crads  box-sizing padding-30">
			<u--form labelPosition="left" :model="form" :rules="rules" ref="uForm" :labelWidth="90">
				<u-form-item label="陪学日期" prop="px_date" borderBottom ref="item1" required
					@click="datetimeShow = true;">
					<u--input :customStyle="{ 'pointer-events': 'none' }" v-model="form.px_date" disabled
						disabledColor="#ffffff" placeholder="请选择陪学日期" border="none"></u--input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>
				<u-form-item label="巡视时间" prop="start_timeName" borderBottom @click="start_timeShow = true;" required
					ref="item1">
					<u--input :customStyle="{ 'pointer-events': 'none' }" v-model="form.start_timeName" disabled
						disabledColor="#ffffff" placeholder="请选择巡视时间" border="none"></u--input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>
				<!-- <u-form-item label="结束时间" prop="end_time" borderBottom @click="end_timeShow = true;" required
					ref="item1">
					<u--input v-model="form.end_time" disabled disabledColor="#ffffff" placeholder="请选择结束时间"
						border="none"></u--input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item> -->
				<!-- 	<u-form-item label="学习态度" prop="Learn_status" borderBottom  ref="item1">
					<u-radio-group 
					    v-model="form.Learn_status"
					    placement="row">
						<u-radio activeColor="red" :name = "1" label=" 积极 "></u-radio>   
						<u-radio activeColor="red" :name = "2" label=" 正常 "></u-radio>  
						<u-radio activeColor="red" :name = "3" label=" 消极 "></u-radio>  
					</u-radio-group>
				</u-form-item> -->


				<!-- <u-form-item label="年级" prop="grade_name" borderBottom @click="grade_nameShow = true;" ref="item1">
					<u--input v-model="form.grade_name" disabled disabledColor="#ffffff" placeholder="请选择年级"
						border="none"></u--input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item> -->
				<u-form-item label="科目" prop="subject_name" borderBottom @click="subject_idShow = true;" required
					ref="item1">
					<u--input :customStyle="{ 'pointer-events': 'none' }" v-model="form.subject_name" disabled
						disabledColor="#ffffff" placeholder="请选择科目" border="none"></u--input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>

				<u-form-item v-show="form.subject_id" label="学案" prop="xuean_name" borderBottom
					@click="xuean_nameShow = true;" ref="item1">
					<u--input :customStyle="{ 'pointer-events': 'none' }" v-model="form.xuean_name" disabled
						disabledColor="#ffffff" placeholder="请选择学案" border="none"></u--input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>
				<u-form-item label="模式" prop="learn_mode" borderBottom ref="item1">
					<u-radio-group @change="learn_modeChange" v-model="form.learn_mode" placement="row">
						<u-radio activeColor="red" :name="1" label=" 同步 "></u-radio>
						<u-radio activeColor="red" :name="2" label=" 综合 "></u-radio>
						<u-radio activeColor="red" :name="3" label=" 其他 "></u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item label="课本" prop="book_name" borderBottom @click="bookShow = true;" ref="item1">
					<u--input v-model="form.book_name" disabled disabledColor="#ffffff" placeholder="请选择课本"
						border="none"></u--input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>
				<u-form-item v-if="form.learn_mode == 1" label="学习章节" prop="chapter_name" borderBottom
					@click="treeShow = true" ref="item1">
					<u--input :customStyle="{ 'pointer-events': 'none' }" v-model="form.chapter_name" disabled
						disabledColor="#ffffff" placeholder="请选择学习章节" border="none"></u--input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>
				<u-form-item v-if="form.learn_mode == 2" label="模块" prop="module_name" borderBottom
					@click="module_nameShow = true" ref="item1">
					<u--input :customStyle="{ 'pointer-events': 'none' }" v-model="form.module_name" disabled
						disabledColor="#ffffff" placeholder="请选择模块" border="none"></u--input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>
				<!-- <u-form-item v-if="form.learn_mode == 2&&form.subject_id" label="模块" prop="module_name" borderBottom @click="module_nameShow = true"  ref="item1">
					<u--input :customStyle = "{'pointer-events':'none'}" v-model="form.module_name" disabled disabledColor="#ffffff" placeholder="请选择模块"
						border="none"></u--input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item> -->
				<u-form-item v-if="form.subject_id && form.learn_mode != '3'" label="出处" prop="source_name" borderBottom
					@click="sourceShow = true;" ref="item1">
					<u--input :customStyle="{ 'pointer-events': 'none' }" v-model="form.source_name" disabled
						disabledColor="#ffffff" placeholder="请选择出处" border="none"></u--input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>
				<u-form-item label="学习类型" prop="pxtypeName" borderBottom @click="pxtypeShow = true;" ref="item1">
					<u--input :customStyle="{ 'pointer-events': 'none' }" v-model="form.pxtypeName" disabled
						disabledColor="#ffffff" placeholder="请选择学习类型" border="none"></u--input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>

				<u-form-item label="用时" prop="learn_duration" borderBottom ref="item1">
					<!-- <u--input v-model="form.learn_duration" placeholder="请输入学习用时" border="none"></u--input> -->
					<view class="flex items-center">
						<u--input v-model="form.learn_duration" placeholder="请输入学习用时" border="none"></u--input>
						<span style="margin-left: 20rpx;">分钟</span>
					</view>
				</u-form-item>

				<u-form-item label="数量" prop="num" borderBottom ref="item1">
					<u--input v-model="form.num" placeholder="请输入数量" border="none"></u--input>
				</u-form-item>
				<u-form-item v-if="form.pxtype == '12'" :label="it.label" :key="it.tabindex"
					v-for="(it, key) in subject_rules[form.subject_name != '化学' && form.subject_name != '物理' ? '数学' : form.subject_name]"
					prop="module_name" borderBottom ref="item1">
					<view class="flex items-center">
						<u-input borderBottom @blur="(e) => inputVal(e, it.name)" v-model="form[it.name]"
							:placeholder="it.placeholder"></u-input>
						<span style="margin-left: 20rpx;" v-if="it.append">{{ it.append }}</span>
					</view>
				</u-form-item>
				<u-form-item
					v-if="form.pxtype == '13' || form.pxtype == '20' || form.pxtype == '30' || form.pxtype == '50' || form.pxtype == '60' || form.pxtype == '70'"
					label="第几题" prop="tihao" borderBottom ref="item1">
					<view class="flex items-center">
						<u--input v-model="form.tihao" placeholder="请输入第几题" border="none"></u--input>
					</view>
				</u-form-item>
				<u-form-item
					v-if="form.pxtype == '13' || form.pxtype == '20' || form.pxtype == '30' || form.pxtype == '50' || form.pxtype == '60' || form.pxtype == '70'"
					label="第几遍" prop="cishu" borderBottom ref="item1">
					<view class="flex items-center">
						<u--input v-model="form.cishu" placeholder="请输入第几遍" border="none"></u--input>
					</view>
				</u-form-item>
				<u-form-item v-if="form.pxtype == '40'" label="自然延伸" prop="zhiyan_num" borderBottom ref="item1">
					<view class="flex items-center">
						<u--input v-model="form.zhiyan_num" placeholder="请输入整理自然延伸关系数量" border="none"></u--input>
						<span style="margin-left: 20rpx;">个</span>
					</view>
				</u-form-item>
				<u-form-item v-if="form.pxtype == '40'" label="关系延伸" prop="guanxi_num" borderBottom ref="item1">
					<view class="flex items-center">
						<u--input v-model="form.guanxi_num" placeholder="请输入整理关系延伸关系数量" border="none"></u--input>
						<span style="margin-left: 20rpx;">个</span>
					</view>
				</u-form-item>
				<u-form-item v-if="form.pxtype == '15' || form.pxtype == '14'" label="开始页码" prop="page_num" borderBottom
					ref="item1">
					<view class="flex items-center">
						<u--input v-model="form.page_num" placeholder="请输入开始页码" border="none"></u--input>
						<span style="margin-left: 20rpx;">页</span>
					</view>
				</u-form-item>
				<u-form-item v-if="form.pxtype == '15' || form.pxtype == '14'" label="结束页码" prop="end_num" borderBottom
					ref="item1">
					<view class="flex items-center">
						<u--input v-model="form.end_num" placeholder="请输入结束页码" border="none"></u--input>
						<span style="margin-left: 20rpx;">页</span>
					</view>
				</u-form-item>
				<u-form-item label="学习状态" prop="Learn_status" borderBottom ref="item1">
					<u-radio-group v-model="form.Learn_status" placement="row">
						<u-radio :name="1" activeColor="red" label="积极"></u-radio>
						<u-radio :name="2" activeColor="red" label="正常"></u-radio>
						<u-radio :name="3" activeColor="red" label="消极"></u-radio>
					</u-radio-group>
				</u-form-item>
				<!-- <u-form-item  label="是否偏离" prop="is_deviate" borderBottom ref="item1">
					<u-radio-group
					    v-model="form.is_deviate"
					    placement="row">
						<u-radio :name = "0" activeColor="red" label="正常"></u-radio>
						<u-radio :name = "1" activeColor="red" label="偏离"></u-radio>
					</u-radio-group>
				</u-form-item> -->
				<!-- <u-form-item label="是否偏离" prop="is_deviate" borderBottom ref="item1">
					<u-radio-group
					    v-model="form.is_deviate"
					    placement="row">
						<u-radio :name = "0" activeColor="red" label="正常"></u-radio>
						<u-radio :name = "1" activeColor="red" label="偏离"></u-radio>
					</u-radio-group>
				</u-form-item> -->

				<u-form-item label="学习速度" prop="is_slow" borderBottom ref="item1">
					<u-radio-group v-model="form.is_slow" placement="row">
						<u-radio :name="1" activeColor="red" label="正常"></u-radio>
						<u-radio :name="0" activeColor="red" label="偏慢"></u-radio>
						<u-radio :name="2" activeColor="red" label="偏快"></u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item label="学习内容" prop="content" borderBottom ref="item1">

					<view class="flex column" style="width: 100%;">
						<view class="" style="display: none;">
							{{ num }}
						</view>
						<u--textarea v-model="form.content" placeholder="请输入学习内容"></u--textarea>
						<u-gap height="20" bgColor="#fff"></u-gap>
						<u-button @click="setText" type="primary" text="自动填充内容"></u-button>
					</view>

				</u-form-item>
				<!-- <u-form-item label="内容填充" borderBottom ref="item1">
					<u-button @click="setText" type="primary" text="自动填充内容"></u-button>
				</u-form-item> -->
				<u-form-item label="备注" prop="remarks" borderBottom ref="item1">
					<u--textarea v-model="form.remarks" placeholder="请输入备注"></u--textarea>
				</u-form-item>
				<u-form-item label="配图" prop="image" borderBottom ref="item1">
					<!-- #ifdef H5  -->
					<u-upload accept="file" :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" :maxCount="1"></u-upload>
					<!-- #endif -->
					<!-- #ifdef APP-PLUS -->
					<u-upload accept="image" :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" :maxCount="1"></u-upload>
					<!-- #endif -->
					<!-- #ifdef MP-WEIXIN -->
					<u-upload accept="all" :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" :maxCount="1"></u-upload>
					<!-- #endif -->
				</u-form-item>
				<!-- <u-form-item
								label="学习学法"
								prop="method_id"
								borderBottom
								@click="method_idShow = true;"
								ref="item1"
						>
							<u--input
									v-model="form.method_id"
									disabled
									disabledColor="#ffffff"
									placeholder="请选择学习学法"
									border="none"
							></u--input>
							<u-icon
									slot="right"
									name="arrow-right"
							></u-icon>
						</u-form-item> -->
			</u--form>

		</view>
		<!-- <view class="operation flex box-sizing space-around items-center">
			<view @click="$u.throttle(submit, 500)" class="flex flex-center items-center fontSize-30 color-white">
				提交
			</view>
		</view> -->
		<!-- <u-datetime-picker
			:show="datetimeShow"
			v-model="form.px_date"
			mode="date"
			@cancel = "datetimeShow = false"
			@confirm = "datetimeClick"
		></u-datetime-picker> -->
		<u-calendar :minDate="minDate" :show="datetimeShow" closeOnClickOverlay @confirm="datetimeClick"
			@close="datetimeShow = false"></u-calendar>
		<!-- @confirm = "(e)=>form.px_date = e" -->
		<!-- <u-datetime-picker :show="start_timeShow" v-model="form.start_time" @cancel="start_timeShow = false"
			@confirm="(e)=>timeConfirm(e,'start_time','start_timeShow')" mode="time"></u-datetime-picker>
		<u-datetime-picker :show="end_timeShow" v-model="form.end_time" mode="time" @cancel="end_timeShow = false"
			@confirm="(e)=>timeConfirm(e,'end_time','end_timeShow')"></u-datetime-picker> -->
		<!-- 出处 -->
		<u-picker :show="sourceShow" :columns="sources" keyName="label" closeOnClickOverlay @close="sourceShow = false"
			@cancel="sourceShow = false" @confirm="sourceConfirm"></u-picker>
		<!-- 巡视时间 -->
		<u-picker :show="start_timeShow" :columns="sjds" keyName="label" closeOnClickOverlay
			@close="start_timeShow = false" @cancel="start_timeShow = false"
			@confirm="start_timeShowConfirm"></u-picker>
		<!-- 课本 -->
		<u-picker :show="bookShow" :columns="book_ids" keyName="label" closeOnClickOverlay @close="bookShow = false"
			@cancel="bookShow = false" @confirm="bookConfirm"></u-picker>

		<!-- <u-picker :show="subject_idShow" :columns="subject_idData" keyName="name" closeOnClickOverlay @close="subject_idShow = false" @cancel="subject_idShow = false"
			@confirm="subjectChange"></u-picker> -->
		<!-- 科目 -->
		<u-picker :show="subject_idShow" :columns="subject_idData" keyName="name" closeOnClickOverlay
			@close="subject_idShow = false" @cancel="subject_idShow = false" @confirm="subjectChange"></u-picker>
		<!-- 学案 -->
		<u-picker :show="xuean_nameShow" :columns="xueanData" keyName="label" closeOnClickOverlay
			@close="xuean_nameShow = false" @cancel="xuean_nameShow = false" @confirm="xueanChange"></u-picker>
		<!-- 年级 -->
		<u-picker :show="grade_nameShow" :columns="grade_nameData" keyName="name" closeOnClickOverlay
			@close="grade_nameShow = false" @cancel="grade_nameShow = false" @confirm="grade_nameChange"></u-picker>
		<!-- 陪学类型 -->
		<u-picker :show="pxtypeShow" :columns="pxtypeData" keyName="name" closeOnClickOverlay
			@close="pxtypeShow = false" @cancel="pxtypeShow = false" @confirm="pxtypeChange"></u-picker>
		<!-- <next-tree :ifSearch="false" valueKey="value" :selectParent="false" :checkStrictly="true" funcMode="checkbox"
			ref="nextTreeAsyncRef" :treeData="asyncTreeData" @cancel="closeTree" @confirm="treeConfirm" /> -->
		<!-- <next-tree :ifSearch="false" :selectParent="true" :checkStrictly="true" funcMode="checkbox"
				ref="nextTreeAsyncRef" :treeData="asyncTreeData" @cancel="closeTree" @confirm="treeConfirm" /> -->
		<!-- 章节tree -->
		<u-popup bgColor="#fff" :round="10" :show="treeShow" @close="treeClose" @open="treeShow = true">
			<view class="popupTreeBox">
				<DaTreeVue2 ref="DaTreeRef1" :data="asyncTreeData" labelField="label" valueField="value"
					showCheckbox :defaultCheckedKeys="defaultCheckedKeysValue"
					@change="handleTreeChange" @expand="handleExpandChange" />
			</view>
		</u-popup>
		<!-- 模块tree -->
		<u-popup bgColor="#fff" :round="10" :show="module_nameShow" @close="moduleTreeClose"
			@open="module_nameShow = true">
			<view class="popupTreeBox">
				<DaTreeVue2 ref="DaTreeRef" :data="moduleTreeData" labelField="label" valueField="value"
					 showCheckbox :defaultCheckedKeys="moduleDefaultCheckedKeysValue"
					@change="modulHeandleTreeChange" @expand="modulHeandleExpandChange" />
			</view>
		</u-popup>
	</view>
</template>

<script>
const d = new Date()
const year = d.getFullYear()
let month = d.getMonth() + 1
month = month < 10 ? `0${month}` : month
const date = d.getDate()
import DaTreeVue2 from '@/components/da-tree-vue2/index.vue'
import { chooseFile } from '../../uni_modules/uview-ui/components/u-upload/utils'
export default {
	components: {
		DaTreeVue2
	},
	data() {
		return {
			num: 0,
			book_name: '',
			minDate: `${year}-${month - 1}-${date}`,
			stuentInfo: {},
			learn_mode: '',
			fileList1: [],
			studentSubjectData: [],
			defaultCheckedKeysValue: [],
			asyncTreeData: [],

			moduleDefaultCheckedKeysValue: [],
			moduleTreeData: [],
			datetimeShow: false,
			start_timeShow: false,
			end_timeShow: false,
			subject_idShow: false,
			method_idShow: false,
			grade_nameShow: false,
			treeShow: false,
			module_nameShow: false,
			pxtypeShow: false,
			xuean_nameShow: false,
			bookShow: false,
			sourceShow: false,
			infoList: [],
			xueanData: [[]],
			sjds: [
				[]
			],
			subject_idData: [
				[]
			],
			pxtypeData: [
				[]
			],
			grade_nameData: [
				[]
			],
			sources: [[]],
			book_ids: [[]],
			form: {
				fileway:'',
				source_id: '',
				source_name: '',
				is_deviate: 0,
				Learn_status: 1,
				is_slow: 1,
				book_id: '',
				book_name: '',
				learn_mode: 1,
				student_id: '',
				px_date: '',
				start_time: '',
				start_timeName: '',
				subject_name: '',
				subject_id: '',
				grade_name: '',
				grade_id: '',
				pxtype: '',
				pxtypeName: '',
				chapter_name: '',
				chapter_id: '',
				module_name: '',
				module_id: '',
				Learn_status: 2,
				xuean_id: '',
				xuean_name: '',
				learn_duration: '',
				value1: '',
				value2: '',
				value3: '',
				value4: '',
				value5: '',
				value6: '',
				tihao: '',
				cishu: '',
				zhiyan_num: '',
				guanxi_num: '',

			},
			rules: {
				'px_date': {
					type: 'string',
					required: true,
					message: '请选择陪学日期',
					trigger: ['change']
				},
				'start_timeName': {
					type: 'string',
					required: true,
					message: '请选择巡视时间',
					trigger: ['change']
				},
				'subject_name': {
					type: 'string',
					required: true,
					message: '请选择科目',
					trigger: ['change']
				},
				// 'content': {
				// 	type: 'string',
				// 	required: true,
				// 	message: '请输入学习内容',
				// 	trigger: ['blur']
				// },
				// 'pxtypeName': {
				// 	type: 'string',
				// 	required: true,
				// 	message: '请选择学习类型',
				// 	trigger: ['change']
				// },
			},
			// 科目校验
			subject_rules: {
				'化学': {
					'value1': {
						name: 'value1',
						label: '概念',
						placeholder: '请输入概念',
						tabindex: 23,
						append: '个'
					},
					'value2': {
						name: 'value2',
						label: '物质库',
						placeholder: '请输入物质库',
						tabindex: 25,
						append: '个'
					},
					'value3': {
						name: 'value3',
						label: '反应库',
						placeholder: '请输入反应库',
						tabindex: 27,
						append: '个'
					},
					'value4': {
						name: 'value4',
						label: '现象库',
						placeholder: '请输入现象库',
						tabindex: 29,
						append: '个'
					},
					'value5': {
						name: 'value5',
						label: '分析库',
						placeholder: '请输入分析库',
						tabindex: 31,
						append: '个'
					},
					'value6': {
						name: 'value6',
						label: '实验',
						placeholder: '请输入实验',
						tabindex: 33,
						append: '个'
					}
				},
				'物理': {
					'value1': {
						name: 'value1',
						label: '概念',
						placeholder: '请输入概念',
						tabindex: 23,
						append: '个'
					},
					'value2': {
						name: 'value2',
						label: '物理公式',
						placeholder: '请输入物理公式',
						tabindex: 25,
						append: '个'
					},
					'value3': {
						name: 'value3',
						label: '物理量',
						placeholder: '请输入物理量',
						tabindex: 27,
						append: '个'
					},
				},
				'数学': {
					'value1': {
						name: 'value1',
						label: '概念',
						placeholder: '请输入概念',
						tabindex: 23,
						append: '个'
					},
					'value2': {
						name: 'value2',
						label: '公式',
						placeholder: '请输入公式',
						tabindex: 25,
						append: '个'
					},
				}
			}
		};
	},
	watch: {
		form: {
			deep: true, immediate: false,
			handler(val) {
				if (val.subject_id || val.book_id || val.student_id || val.learn_mode) {
					this.getInfo()
				}
			}
		}
	},
	onLoad(op) {
		this.form.student_id = op.student_id
		this.learn_mode = op.learn_mode
		this.stuentInfo['name'] = op.name
		this.stuentInfo['student_id'] = op.student_id
		this.stuentInfo['learn_mode'] = op.learn_mode
		// this.learn_mode = 2
		// this.studentSubject()
		this.getInfo()
		this.getlastpx()
		let date = new Date()
		let year = date.getFullYear();
		let month = date.getMonth() + 1;
		let day = date.getDate();
		let hour = date.getHours();
		let minute = date.getMinutes();
		let second = date.getSeconds();
		this.form.px_date = year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day)
		// this.form.start_time = date.getHours()+':'+date.getMinutes()
		// this.form.end_time = date.getHours()+':'+date.getMinutes()


	},
	methods: {
		chooseFile() {
			uni.chooseFile({
				success: (res => {
					console.log(JSON.stringify(res.tempFilePaths));
				})
			})
		},
		getlastpx() {
			this.$home.getlastpx({ student_id: this.form.student_id, subject_id: this.form.subject_id }).then(res => {
				let info = res
				this.form['student_id'] = this.form.student_id
				// this.form['Learn_status'] = info.Learn_status&&info.Learn_status != 0 ? info.Learn_status : 2
				// this.form['learn_mode'] = info.learn_mode?info.learn_mode:1
				// this.form['subject_id'] = info.subject_id?info.subject_id:''
				this.form['subject_name'] = info.setsubject_name ? info.setsubject_name : ''
				// this.form['xuean_id'] = info.xuean_id?info.xuean_id:''
				this.form['xuean_name'] = info.xuean_title ? info.xuean_title : ''
				// this.form['pxtype'] = info.pxtype?info.pxtype:''
				this.form['pxtypeName'] = info.pxtype_name ? info.pxtype_name : ''
				this.form['chapter_name'] = info.learn_mode == 1 ? info.chaptername : ''
				// this.form['chapter_id'] = info.chapter_id ? info.chapter_id.split(',') : [],
				this.form['module_name'] = info.learn_mode == 2 ? info.chaptername : ''
				this.form['source_name'] = info.sourcename ? info.sourcename : ''
				// 课本
				// this.form['module_id'] = info.module_id ? info.module_id.split(',') : [],
				for (const k of Object.keys(info)) {
					this.form[k] = info[k]
				}
				info.learn_mode == 1 ? this.form['chapter_id'] = info.chapter_id ? info.chapter_id.split(',') : [] : this.form['module_id'] = info.chapter_id ? info.chapter_id.split(',') : []
				this.defaultCheckedKeysValue = info.learn_mode == 1 ? [...this.form.chapter_id] : []
				this.moduleDefaultCheckedKeysValue = info.learn_mode == 2 ? [...this.form.chapter_id] : []
				if (info.xuean_id == 0) {
					//this.form['content'] = '休息'
					this.form.content = '休息'
				}
				if (info.subject_id && info.learn_mode) {
					this.getInfo()
					this.setTreeData()
				}
			})
		},
		inputClick() {
		},
		learn_modeChange(e) {
			if (e && e == 1) {
				this.form.module_name = ''
				this.form.module_id = ''
				this.form.book_id = ''
				this.form.book_name = ''
				this.book_ids = [[]]
				this.setEmpty()
			} else if (e && e == 2) {
				this.form.chapter_name = ''
				this.form.chapter_id = ''
				this.form.book_id = ''
				this.form.book_name = ''
				this.book_ids = [[]]
				this.setEmpty()
			} else if (e && e == 3) {
				this.form.module_name = ''
				this.form.module_id = ''
				this.form.chapter_name = ''
				this.form.chapter_id = ''
				this.form.book_id = ''
				this.form.book_name = ''
				this.setValEmpty()
				// this.setEmpty()
			}
			// this.getInfo()
			this.setTreeData()
		},
		setTreeData() {
			let data = []
			this.$home.getChapterInfo({ student_id: this.form.student_id, subject_id: this.form.subject_id, learn_mode: this.form.learn_mode, book_id: this.form.book_id }).then(res => {
				this.asyncTreeData = res.chapter_ids
				this.moduleTreeData = res.chapter_ids
				this.book_name = res.book_name
				this.xueanData = res.xuean_ids ? [[...res.xuean_ids]] : [[]]
			})

		},
		openTree() {
			this.$refs.nextTreeAsyncRef.showTree = true
		},
		closeTree() {
			this.$refs.nextTreeAsyncRef.showTree = false
		},
		treeConfirm(e) {

		},
		handleTreeChange(allSelectedKeys, currentItem) {
			this.form.chapter_id = [...allSelectedKeys]
			this.form.chapter_name = ''
			// console.log( this.$refs.DaTreeRef1.getCheckedNodes(),66666)
			let checks = this.$refs.DaTreeRef1.getCheckedNodes()
			// originItem
			if (checks) {
				// let items = checks
				this.setVal(checks, 'chapter_name')
			}
			// if(currentItem&&currentItem.checkedStatus!=0){
			//  // this.form.chapter_name = currentItem.label
			//  this.form.chapter_name = this.selectVal(currentItem.label, this.form.chapter_name)
			//  console.log(this.form.chapter_name,'*********')
			// }else{
			//  // this.defaultCheckedKeysValue.indexOf(currentItem.key)>-1?this.form.chapter_name = '':''
			// }
		},
		setVal(list, key, labelKey = 'label') {
			if (list && list.length > 0) {
				list.map(e => {
					this.form[key] += e.label + ';'
				})
			}
		},
		setValEmpty() {
			// this.form.book_id = ''
			// this.form.book_name = ''
			this.form.value1 = null
			this.form.value2 = null
			this.form.value3 = null
			this.form.value4 = null
			this.form.value5 = null
			this.form.value6 = null
			this.form.tihao = null
			this.form.cishu = null
			this.form.zhiyan_num = null
			this.form.guanxi_num = null
			this.form.page_num = null
			this.form.end_num = null
		},
		setEmpty() {
			this.form.source_name = ''
			this.form.source_id = ''
			this.source_ids = []
			this.form.chapter_id = []
			this.form.chapter_name = ''
			this.form.module_id = []
			this.form.module_name = ''
			this.form.pxtype = ''
			this.form.pxtypeName = ''
			this.form.xuean_id = ''
			this.form.xuean_name = ''
			this.asyncTreeData = []
			this.defaultCheckedKeysValue = []
			this.moduleTreeData = []
			this.moduleDefaultCheckedKeysValue = []
		},
		inputVal(e, key) {
			this.form[key] = e
		},
		treeClose() {
			this.defaultCheckedKeysValue = [...this.form.chapter_id]
			this.treeShow = false
		},
		handleExpandChange(expand, currentItem) {

			// console.log( this.$refs.DaTreeRef1.getCheckedNodes(),66666)

			// console.log('handleExpandChange ==>', expand, currentItem)
		},
		modulHeandleTreeChange(allSelectedKeys, currentItem) {
			// console.log('handleTreeChange ==>', allSelectedKeys, currentItem,currentItem.length)
			this.form.module_id = [...allSelectedKeys]
			// this.form.module_name = this.selectVal(currentItem.label, this.form.module_name)
			// console.log( this.$refs.DaTreeRef.getCheckedNodes(),66666)
			this.form.module_name = ''
			// console.log( this.$refs.DaTreeRef1.getCheckedNodes(),66666)
			let checks = this.$refs.DaTreeRef.getCheckedNodes()
			// originItem
			if (checks) {
				// let items = checks.originItem
				this.setVal(checks, 'module_name')
			}
			// if(currentItem&&currentItem.checkedStatus!=0){
			//  this.form.module_name = this.selectVal(currentItem.label, this.form.module_name)
			//  console.log(this.form.module_name,'*********')
			// }else{
			//  // this.defaultCheckedKeysValue.indexOf(currentItem.key)>-1?this.form.chapter_name = '':''
			// }
		},
		selectVal(val, texts) {
			if (texts.search(val) != -1) {
				texts = texts.split(val + ';').join('')
			} else {
				texts += val + ';'
			}
			return texts
		},
		moduleTreeClose() {
			this.moduleDefaultCheckedKeysValue = [...this.form.module_id]
			this.module_nameShow = false
		},
		modulHeandleExpandChange(expand, currentItem) {
			// console.log( this.$refs.DaTreeRef.getCheckedNodes(),66666)
			// this.$refs.DaTreeRef.getCheckedNodes()
			// console.log('handleExpandChange ==>', expand, currentItem)
		},
		// studentSubject() {
		// 	this.$home.studentSubject({
		// 		student_id: this.form.student_id
		// 	}).then(res => {
		// 		this.subject_idData[0] = res.data
		// 		console.log(res.data, 6666)
		// 	})
		// },
		setText() {
			// this.recursionVal('chapter_name', this.asyncTreeData);
			// this.recursionVal('module_name', this.moduleTreeData);
			let book_name = this.form.book_name ? '课本名称:' + this.form.book_name : '';
			let chapter_name = this.form.chapter_name ? '章节:' + this.form.chapter_name : '';
			let module_name = this.form.module_name ? '模块:' + this.form.module_name : '';
			let page_num = this.form.page_num ? '开始页码:第 ' + this.form.page_num : '';
			let end_num = this.form.end_num ? '结束页码:第 ' + this.form.end_num : '';
			let num = this.form.num ? '数量:' + this.form.num : '';
			let source_name = this.form.source_name ? '出处:' + this.form.source_name : '';

			// setTimeout(() => {
			this.$nextTick(() => {
				this.num++
				this.form.content =
					`${book_name ? book_name + '\n' : ''}${chapter_name ? chapter_name + '\n' : ''}${page_num ? page_num + ' 页' + '\n' : ''}${end_num ? end_num + ' 页' + '\n' : ''}${num ? num + '\n' : ''}${source_name ? source_name + '\n' : ''}`
			})
			// }, 1000)
		},
		recursionVal(key, list) {
			for (const t of list) {
				if (this.values[key][t.value]) {
					this.values[key][t.value] = t.label
					let index = this.contentVal[key].indexOf(t.label)
					if (index == -1) {
						this.contentVal[key] += t.label + ';'
					}
				} else if (t.children && t.children.length > 0) {
					this.recursionVal(key, t.children)
				}
			}
		},
		subjectChange(e) {
			if (e && e.value && e.value.length > 0) {
				this.form.subject_id = e.value[0].tag
				this.form.subject_name = e.value[0].name

				this.moduleDefaultCheckedKeysValue = []
				this.defaultCheckedKeysValue = []
				this.asyncTreeData = []
				this.moduleTreeData = []
				this.xueanData = [[]]
				this.form.chapter_name = ''
				this.form.chapter_id = ''
				this.form.module_name = ''
				this.form.module_id = ''
				this.form.xuean_name = ''
				this.form.xuean_id = ''
				this.form.book_id = ''
				this.form.book_name = ''
				this.form.pxtypeName = ''
				this.form.pxtype = null
				this.book_ids = [[]]
				// this.form.source_name =  ''
				// this.form.source_id =  ''
				// this.source_ids =  []
				this.setEmpty()
				this.setValEmpty()
				this.setTreeData()
				this.getlastpx()
				// this.getInfo()
			}
			this.subject_idShow = false
		},
		bookConfirm(e) {
			console.log(e, 555555)
			if (e && e.value && e.value.length > 0) {
				this.form.book_id = e.value[0].value
				this.form.book_name = e.value[0].label
			}

			// if (e && e.value && e.value.length > 0) {
			// 	this.form.book_id = e.value[0].value
			// 	this.form.book_name = e.value[0].label
			// }
			// this.getInfo()
			this.setTreeData()
			this.bookShow = false
		},
		// 出处
		sourceConfirm(e) {
			if (e && e.value && e.value.length > 0) {
				this.form.source_id = e.value[0].value
				this.form.source_name = e.value[0].label
			}
			this.sourceShow = false
		},
		start_timeShowConfirm(e) {
			if (e && e.value && e.value.length > 0) {
				this.form.start_time = e.value[0].value
				this.form.start_timeName = e.value[0].label
			}
			this.start_timeShow = false
		},
		grade_nameChange(e) {
			if (e && e.value && e.value.length > 0) {
				this.form.grade_id = e.value[0].tag
				this.form.grade_name = e.value[0].name
			}
			this.grade_nameShow = false
		},
		pxtypeChange(e) {
			if (e && e.value && e.value.length > 0) {
				this.form.pxtype = e.value[0].tag
				this.form.pxtypeName = e.value[0].name
				this.setValEmpty()
			}
			this.pxtypeShow = false
		},
		getInfo() {
			let that = this
			this.$home.getInfo({ student_id: this.form.student_id, subject_id: this.form.subject_id, learn_mode: this.form.learn_mode }).then(res => {
				that.infoList = res
				// if(that.book_ids[0].length==0){
				that.book_ids = res.book_ids ? [[...res.book_ids]] : [[]]
				if (res.book_ids && res.book_ids.length > 0) {
					let ids = res.book_ids.map(c => c.value).indexOf(that.form.book_id)
					that.form.book_name = ids > -1 ? res.book_ids[ids].label : ''
				}
				// }
				that.sources = res.source_ids ? [[...res.source_ids]] : [[]]
				that.sjds = res.sjds ? [[...res.sjds]] : [[]]
				// that.subject_idData = res.subject_ids?[[...res.subject_ids]]:[[]]
				that.subject_idData = res.subject_ids ? [[...res.subject_ids]] : [[]]
				that.grade_nameData = res.grade_ids ? [[...res.grade_ids]] : [[]]
				that.pxtypeData = res.pxtypes ? [[...res.pxtypes]] : [[]]
				let times = res.sjds
				if (times && times.length > 0) {
					let date = new Date()
					let defaultHour = date.getHours();
					let defaultMinute = date.getMinutes();
					for (const e of times) {
						let s = { ...e }
						let timeArr = s.label.split('-');
						let startTime = timeArr[0].split(':');
						let endTime = timeArr[1].split(':');
						if (!that.form.start_timeName) {
							if (defaultHour > startTime[0] || defaultHour == startTime[0] && defaultMinute > startTime[1]) {
								if (defaultHour < endTime[0] || defaultHour == endTime[0] && defaultMinute < endTime[1]) {
									this.$nextTick(() => {
										that.form.start_time = parseInt(e.value)
										that.form.start_timeName = e.label
									})
								}
							}
						}

					}
				}
			})
		},
		datetimeClick(e) {
			if (e && e.length > 0) {
				this.form.px_date = e[0]
			}
			this.datetimeShow = false
		},
		xueanChange(e) {
			if (e && e.value && e.value.length > 0) {
				this.form.xuean_id = e.value[0].value
				this.form.xuean_name = e.value[0].label
				if (e.value[0].label == '休息') {
					this.form.content = '休息'
				} else {
					this.form.content = this.form.content == '休息' ? '' : this.form.content
				}
			}
			this.xuean_nameShow = false
		},
		timeConfirm(e) {
			if (e && e.value && e.value.length > 0) {
				this.form.start_time = e.value[0].value
				this.form.start_timeName = e.value[0].label
			}
			this.start_timeShow = false
		},
		// 删除图片
		deletePic(event) {
			this.form.fileway = ''
			this[`fileList${event.name}`].splice(event.index, 1)
		},
		// 新增图片
		async afterRead(event) {
			console.log(event,'xxxxxxxxxxxx')
			// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
			let lists = [].concat(event.file)
			let fileListLen = this[`fileList${event.name}`].length
			lists.map((item) => {
				this[`fileList${event.name}`].push({
					...item,
					status: 'uploading',
					message: '上传中'
				})
			})
			for (let i = 0; i < lists.length; i++) {
				console.log(event,event.file,'xxxxxxxxxx')
				// let name = lists[i]&&lists[i].name&&lists[i].name.length>0?lists[i].name.split('.')[1]:['',''];
				// return 
				// let name = lists[i].name?lists[i].name.split('.')[1]:['',''];
				this.form.fileway = event.file&&event.file.type?event.file.type:'image'
				const result = await this.uploadFilePromise(lists[i].url)
				let item = this[`fileList${event.name}`][fileListLen]
				this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
					status: 'success',
					message: '',
					url: result
				}))
				fileListLen++
			}
		},
		uploadFilePromise(url) {
			return new Promise((resolve, reject) => {
				let a = uni.uploadFile({
					url: this.$uploadUrl+'Upload/upload', // 仅为示例，非真实的接口地址
					// url: 'http://bbsf.test/api/Upload/upload', // 仅为示例，非真实的接口地址
					filePath: url,
					name: 'file',
					formData: {
						upload_config_id: 1
					},
					header: {
						token: uni.getStorageSync('token'),
						// 'content-type': 'multipart/form-data'
					},
					success: (res) => {
						resolve(JSON.parse(res.data).data)
					},
					fail: (err) => {
					}
				});
			})
		},
		submit() {
			let form = this.form
			if (!form.px_date || form.px_date == '') {
				return uni.showToast({
					title: '请选择陪学日期',
					icon: 'none'
				})
			}
			if (!form.start_timeName || form.start_timeName == '') {
				return uni.showToast({
					title: '请选择巡视时间',
					icon: 'none'
				})
			}
			if (!form.subject_name || form.subject_name == '') {
				return uni.showToast({
					title: '请选择科目',
					icon: 'none'
				})
			}
			if (form.learn_mode != 3 && form.pxtypeName == '') {
				return uni.showToast({
					title: '请选择学习类型',
					icon: 'none'
				})
			}
			// if(!form.content||form.content == ''){
			// 	return uni.showToast({
			// 		title:'请输入学习内容',
			// 		icon:'none'
			// 	})
			// }
			// if(this.form.xuean_name != '休息'&&!form.pxtypeName||this.form.xuean_name != '休息'&&form.pxtypeName == ''){
			// 	return uni.showToast({
			// 		title:'请选择学习类型',
			// 		icon:'none'
			// 	})
			// }
			// console.log(images,5555)
			// return 
			// this.$refs.uForm.validate().then(res => {
			let defaultUser = uni.getStorageSync('userInfo')
			// let images = []
			
			// if(this.fileList1 && this.fileList1.length > 0){
			let images = [{
				url: this.fileList1 && this.fileList1.length > 0 ? this.fileList1[0].url : ''
			}]
			// }else{
			// 	images = []
			// }
			// return 
			let params = {
				user_id: defaultUser.user_id,
				dept_id: defaultUser.dept_id,
				comp_no: defaultUser.comp_no
			}
			let info = this.form
			params = {
				...params,
				...this.form
			}
			params['images'] = images
			params.chapter_id = info.learn_mode == 3 ? '' : info.learn_mode == 1 ? this.form.chapter_id ? this.form.chapter_id.join() : '' : this.form.module_id ? this.form.module_id.join() : ''
			this.$home.addPxrec(params).then(res => {
				if (res.status == 200) {
					uni.showToast({
						title: '提交成功!',
						icon: 'none'
					})
					uni.navigateBack()
				} else {
					uni.$u.toast('提交失败')
				}
			})


			// }).catch(errors => {
			// 	uni.$u.toast('校验失败')
			// })
		},

	}
}
</script>

<style lang="scss" scoped>
// .u-input{
//   pointer-events: none;
// }
.addAccompany {
	height: 100vh;
	box-sizing: border-box;

	::v-deep .u-radio {
		margin-right: 25rpx;
	}

	.popupTreeBox {
		width: 100%;
		height: 60vh;
		padding-top: 50rpx;
		overflow-y: auto;
		padding-left: 30rpx;
		padding-right: 30rpx;
		box-sizing: border-box;
	}

	.userTitle {
		width: 100%;
		height: 140rpx;
		box-sizing: border-box;
		padding-top: var(--status-bar-height);
		background-color: #fff;
		border-bottom: 1rpx solid #ededed;
	}

	.crads {
		width: 100%;
		height: calc(100vh - 140rpx - 120rpx);
		overflow-y: auto;

		.card {
			width: calc(100% - 60rpx);
			background-color: #f7f7f7;
			color: #333;
		}
	}

	.operation {
		width: 100%;
		height: 120rpx;
		// background-color: #f7f7f7;
		background-color: #fff;

		view {
			width: 80%;
			border-radius: 500rpx;
			padding: 20rpx 0;
			border: 1rpx solid #fff;
			background-color: #ea9700a1;
		}
	}

	.right {}

	.submit {
		width: 120rpx;

		padding: 5rpx 0rpx;
		border-radius: 10rpx;
		border: 1rpx solid #fff;
		background-color: #ea9700a1;
	}
}
</style>